package com.haotunet.app.goldtreasure.views;

import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import com.haotunet.app.goldtreasure.R;

public class MyProgressDialog extends Dialog {

    private AsyncTask<Void, ?, ?> task;

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public MyProgressDialog(Context context) {
        super(context);
    }

    public void onStart() {
        if (task != null) {
            task.execute();
        }
    }

    public void dismiss() {
        super.dismiss();
        task = null;
    }

    public void show() {

        super.show();

    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_loading_dialog);
        setCanceledOnTouchOutside(false);
    }

    public void onBackPressed() {
        super.onBackPressed();
        if (task != null && !task.isCancelled()) {
            task.cancel(true);
        }
    }

    public void setTask(AsyncTask<Void, ?, ?> task) {
        this.task = task;
    }

    public AsyncTask<Void, ?, ?> getTask() {
        return task;
    }

}